package com.dan.service.impl;

import com.dan.pojo.User;
import com.dan.service.UserService;
import com.dan.utils.Md5Util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserService userService;

    @Override
    public User findByUserName(String username) {
        System.out.println("查询员工");
        return userService.findByUserName(username);
    }

    @Override
    public void add(String username, String password) {
        //加密
        String md5String = Md5Util.getMD5String(password);
        userService.add(username, md5String);
    }

    @Override
    public void update(User user) {
        user.setUpdateTime(LocalDateTime.now());
        userService.update(user);
    }

    @Override
    public void updateAvatar(String avatar, Integer id) {
        userService.updateAvatar(avatar, id);
    }

    public void updatePwd(String newPwd, Integer id) {
        String md5String = Md5Util.getMD5String(newPwd);
        userService.updatePwd(md5String, id);
    }
}